package com.business.form.controller.gen;

import com.business.form.model.auto.FormInstanceFieldValue;
import com.business.form.service.FormInstanceFieldValueService;
import com.business.system.common.base.BaseController;
import com.business.system.common.domain.AjaxResult;
import com.business.system.model.custom.TableSplitResult;
import com.business.system.model.custom.Tablepar;
import com.business.system.model.custom.TitleVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("FormInstanceFieldValueController")
@Api(value = "表单实例字段值")
public class FormInstanceFieldValueController extends BaseController{
	
	private String prefix = "gen/formInstanceFieldValue";
	@Autowired
	private FormInstanceFieldValueService formInstanceFieldValueService;
	
	@GetMapping("view")
    public String view(ModelMap model)
    {	
		String str="表单实例字段值";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
        return prefix + "/list";
    }
	
	//@Log(title = "表单实例字段值集合查询", action = "111")
	@PostMapping("list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchTxt){
		PageInfo<FormInstanceFieldValue> page=formInstanceFieldValueService.list(tablepar,searchTxt) ; 
		TableSplitResult<FormInstanceFieldValue> result=new TableSplitResult<FormInstanceFieldValue>(page.getPageNum(), page.getTotal(), page.getList()); 
		return  result;
	}
	
	/**
     * 新增
     */

    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
	//@Log(title = "表单实例字段值新增", action = "111")
	@PostMapping("add")
	@ResponseBody
	public AjaxResult add(FormInstanceFieldValue formInstanceFieldValue){
		int b=formInstanceFieldValueService.insertSelective(formInstanceFieldValue);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	//@Log(title = "表单实例字段值删除", action = "111")
	@PostMapping("remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=formInstanceFieldValueService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 检查用户
	 * @param tsysUser
	 * @return
	 */
	@PostMapping("checkNameUnique")
	@ResponseBody
	public int checkNameUnique(FormInstanceFieldValue formInstanceFieldValue){
		int b=formInstanceFieldValueService.checkNameUnique(formInstanceFieldValue);
		if(b>0){
			return 1;
		}else{
			return 0;
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("FormInstanceFieldValue", formInstanceFieldValueService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "表单实例字段值修改", action = "111")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FormInstanceFieldValue record)
    {
        return toAjax(formInstanceFieldValueService.updateByPrimaryKeySelective(record));
    }


	/**
	 * 根据表单实例id和formFieldName查询表单对应的填写的值
	 * @param formInstanceId
	 * @return
	 */
	@GetMapping("selectformInstanceFieldValue/{formInstanceId}/{formFieldName}")
	@ResponseBody
	public AjaxResult selectformInstanceFieldValueByInstanceId(
			@PathVariable("formInstanceId") String formInstanceId,
			@PathVariable("formFieldName")String formFieldName){
    	FormInstanceFieldValue value =  formInstanceFieldValueService.selectformInstanceFieldValueByInstanceId(formInstanceId,formFieldName);
    	return AjaxResult.successData(200,value);
	}
    

	
}
